package pl.mchaniewski.ryneczek.pojo;

// Generated Oct 3, 2011 3:17:38 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "company", catalog = "stockmarket")
public class Company implements java.io.Serializable {
    private static final long serialVersionUID = -5431737369195061672L;

    private Integer companyid;
    private String name;
    private boolean wasInLastUpdate;
    private Set<Index> indexes = new HashSet<Index>(0);
    private Set<Order> orders = new HashSet<Order>(0);
    private Set<Quotation> quotations = new HashSet<Quotation>(0);

    public Company() {
    }

    public Company(String name, boolean wasInLastUpdate) {
        this.name = name;
        this.wasInLastUpdate = wasInLastUpdate;
    }

    public Company(String name, boolean wasInLastUpdate, Set<Index> indexes,
            Set<Order> orders, Set<Quotation> quotations) {
        this.name = name;
        this.wasInLastUpdate = wasInLastUpdate;
        this.indexes = indexes;
        this.orders = orders;
        this.quotations = quotations;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "COMPANYID", unique = true, nullable = false)
    public Integer getCompanyid() {
        return companyid;
    }

    public void setCompanyid(Integer companyid) {
        this.companyid = companyid;
    }

    @Column(name = "NAME", nullable = false, length = 30)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "WAS_IN_LAST_UPDATE", nullable = false)
    public boolean isWasInLastUpdate() {
        return wasInLastUpdate;
    }

    public void setWasInLastUpdate(boolean wasInLastUpdate) {
        this.wasInLastUpdate = wasInLastUpdate;
    }

    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "companies")
    public Set<Index> getIndexes() {
        return indexes;
    }

    public void setIndexes(Set<Index> indexes) {
        this.indexes = indexes;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
    public Set<Order> getOrders() {
        return orders;
    }

    public void setOrders(Set<Order> orders) {
        this.orders = orders;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
    public Set<Quotation> getQuotations() {
        return quotations;
    }

    public void setQuotations(Set<Quotation> quotations) {
        this.quotations = quotations;
    }

    @Transient
    @Override
    public String toString() {
        return getName();
    }

}
